package com.comsumer.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MQConfig {
    public static final String EXCHANGE_NAME="EXCHANGE_ADD_GOOD";
    public static final String QUEUE_NAME="QUEUE_ADD_GOOD";
    public static final String ROUTINGKEY="ROUTINGKEY_ADD_GOOD";
    @Bean(EXCHANGE_NAME)
    public Exchange exchange(){
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }

    @Bean(QUEUE_NAME)
    public Queue siteQueue(){
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

    @Bean
    public Binding bindingQueueToExchange(@Qualifier(QUEUE_NAME) Queue queue,
                               @Qualifier(EXCHANGE_NAME) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY).noargs();
    }
}
